//
//  BETechListViewModel.swift
//  BEGlobalOiler
//
//  Created by KKING on 2016/10/13.
//  Copyright © 2016年 Bullseye Energy pte ltd. All rights reserved.
//

import UIKit

class BETechListViewModel: NSObject {
    //懒加载视图模型数组
    lazy var techVModelDatas: [BETechCellVM] = [BETechCellVM]()
}

extension BETechListViewModel{
    
    func loadTechListData(finished: @escaping (_ success: Bool, _ tip: String) -> ()) {
        BENetworkTools.shareNetworkTool.loadTechListData{ (success, result, error) in
            
            guard let resultjson = result else {
                finished(false, "Network fault!")
                return
            }
            if resultjson["success"] == true {
                //此处增加字典转模型逻辑
                let data = resultjson["result"].arrayObject as! [[String : AnyObject]]
                for item in data{
                    let tech = BETechModel(dict: item)
                    let viewMdl = BETechCellVM(techModel: tech)
                    // mark 数据重复,需增加逻辑判断.
                    self.techVModelDatas.append(viewMdl)
                }
                finished(true, "Load data success!")
            } else {
                finished(false, resultjson["message"].stringValue)
            }
            
        }
    }
}
